package com.thalesgroup.nl.trtdelft.dein.mapper.example;

import com.thalesgroup.nl.trtdelft.dein.mapper.AbstractMappedWebService;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author AbdelhaqA
 */
public class Snif extends AbstractMappedWebService {

    private String loginStatus = null;

    @Override
    public void start() {
        super.start();

        // receive data from Login
        String userId = (String) queryReceiveVariableContent.get("userId");
        String passWord = (String) queryReceiveVariableContent.get("passWord");

        HashMap<String, Serializable> qSendContent = new HashMap<>();
        qSendContent.put("userId", userId);
        qSendContent.put("passWord", passWord);

        List<String> capabilities = getRequiredCababilityForQuerySendVariables();

        for (String capability : capabilities) {

            Map<String, Serializable> map = getQuerySendServiceParameterElements(capability);

            if (map.containsKey("userId") && map.containsKey("passWord")) {
                // send data to graphDB
                querySendVariableContent.put(capability, qSendContent);
                sendMapperInformationInterface.sendQuery(capability);
            }
        }
    }
    @Override
    @SuppressWarnings("unchecked")
    public void input(String senderAddress, String inputVariableName, Serializable input) {

        System.out.println("senderAddress=" + senderAddress + "inputVariableName=" + inputVariableName + " input=" + input);

        if (inputVariableName.equals("loginStatus")) {
            // send data to Login
            loginStatus = (String) input;      
            outputs.put("loginStatus", loginStatus); 
          //  sendMapperInformationInterface.sendOutput();
        } 
    }

    @Override
    public void computeOutput() throws IllegalStateException {
    }

    @Override
    public void computeOutput(String variableName) throws IllegalStateException {
        computeOutput();
    }

    @Override
    public Serializable getCurrentOutput(String variableName) throws IllegalStateException {
        return outputs.get(variableName);
    }

}

